package xfuzzy.alg_genetico.indeterminado.selection;

import java.util.ArrayList;
import java.util.List;

import xfuzzy.xfghl.codification.DoubleChromosome;
import xfuzzy.xfghl.population.Population;
import xfuzzy.xfghl.selection.Selection;

public class NegativeAssortativeMating extends Selection {
	
	private int sizeSelection;
	
	public NegativeAssortativeMating(long seed, int size)  {
		
		super(seed);
		this.sizeSelection = size;
	}

	public List<DoubleChromosome> seleccionar(Population poblacion) {
		
		int randomIndex = this.random.nextInt(poblacion.getPoblacionSize());
		DoubleChromosome father1 = poblacion.getIndividuo(randomIndex);
		List<DoubleChromosome> fathers2 = new ArrayList<DoubleChromosome>();
		DoubleChromosome auxiliar = null;
		for (int index = 0; index < this.sizeSelection; index++)  {
			 randomIndex = this.random.nextInt(poblacion.getPoblacionSize());
			 auxiliar = poblacion.getIndividuo(randomIndex);
			 while (fathers2.contains(auxiliar))  {
				 randomIndex = this.random.nextInt(poblacion.getPoblacionSize());
				 auxiliar = poblacion.getIndividuo(randomIndex);
			 }
			 fathers2.add(auxiliar);
		}
		DoubleChromosome father2 = fathers2.get(0);
		//double parentesco = father1.getSimilarity(father2), parentescoAux = 0.0;
//		for (int index = 0; index < this.sizeSelection; index++)  {
//			 parentescoAux = father1.getSimilarity(fathers2.get(index));
//			 if (parentescoAux < parentesco)  {
//				 parentesco = parentescoAux;
//				 father2 = fathers2.get(index);
//			 }
//		}
		List<DoubleChromosome> seleccionados = new ArrayList<DoubleChromosome>();
		seleccionados.add(father1);
		seleccionados.add(father2);
		return seleccionados;
	}
}
